package ru.ifmo.thesis.gp;

import org.jgap.FitnessFunction;
import org.jgap.IChromosome;

import ru.ifmo.thesis.domain.Shedule;
import ru.ifmo.thesis.util.Algorithms;

public class MyFitnessFunction extends FitnessFunction {

	private static final long serialVersionUID = 1L;

	private double currentMax = 0;
	
	public MyFitnessFunction(){
	}
	
	@Override
	protected double evaluate(IChromosome aSubject) {
		Shedule shedule = Algorithms.constructShedule(aSubject);
		double totalCost = Algorithms.calculateSheduleCost(shedule);
		
		if (totalCost > currentMax) {
			currentMax = totalCost;
		}
		
		return currentMax - totalCost;
	}
}